#!/bin/bash
# Backup a database *locally* to /backups/.

# Sleep a bit so we do not have a thundering herd on db hosts
sleep $[ ( $RANDOM % 7200 )  + 1 ]s

DB=anitya

# Make our latest backup
# Make it use a limited number of threads because pxz will use all the
# cpus which causes pg_dump to starve which causes...

/usr/bin/pg_dump --exclude-table-data users --exclude-table-data tokens --exclude-table-data 'social*' --exclude-table-data sessions -C $DB | /usr/bin/pxz -T4 > /backups/$DB-public-$(date +%F).dump.xz

# Also, delete the backup from a few days ago.
rm -f /backups/$DB-public-$(date --date="1 days ago" +%F).dump.xz
